package com.trendit.java_test;

public class SocketTest {


/*    private static String content = "GET /api/firmware_common/latest_version?deviceSn=00003902800200000001&firmwareClass=IBOX_0501&currentFirmwareCode=V0.0.1 HTTP/1.1\r\n" +
            "Host:47.106.157.121:3021\r\n" +
            "Accept: * / *\r\n" +
            "User-Agent: GeneralDownloadApplication\r\n" +
            "Connection: keep-alive\r\n\r\n";*/

    private static String content = "POST /param/download/v1 HTTP/1.1\n" +
            "Host:posapi.iboxpay.com\n" +
            "cache-control: no-cache\n" +
            "Content-Type: application/json\n" +
            "User-Agent: Apache-HttpClient/4.1.1 (java 1.5)\n" +
            "Content-Type: application/json\n" +
            "Connection: Keep-Alive\n" +
            "Content-Length:35\n" +
            "Accept: */*\n" +
            "\n" +
            "{\"deviceSn\":\"00003902800200000001\"}" +
            "\r\n\r\n";

    private static String CERT_INFO = "-----BEGIN CERTIFICATE-----\r\n" +
            "MIID9zCCAt+gAwIBAgIJAM8rN7zT3uP9MA0GCSqGSIb3DQEBBQUAMFoxCzAJBgNV\r\n" +
            "BAYTAmNuMQswCQYDVQQIEwJzZDELMAkGA1UEBxMCcWQxDjAMBgNVBAoTBXFkdW1z\r\n" +
            "MQ0wCwYDVQQLEwRwb3NwMRIwEAYDVQQDEwlxZHVtcy5jb20wHhcNMTQwNjI1MDYz\r\n" +
            "NjEwWhcNMjQwNjIyMDYzNjEwWjBaMQswCQYDVQQGEwJjbjELMAkGA1UECBMCc2Qx\r\n" +
            "CzAJBgNVBAcTAnFkMQ4wDAYDVQQKEwVxZHVtczENMAsGA1UECxMEcG9zcDESMBAG\r\n" +
            "A1UEAxMJcWR1bXMuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA\r\n" +
            "40qduApMe7mJkNAVqYjK4fVx7J//SND1WmDqcPyGl8T6vYOoyzf3IBK1izEE7fc3\r\n" +
            "xwACGM23A/eBSl1V1rryRo5zlvi5QqQZQnTq185znfVD8UaPcn+q7ksjTShP+eyV\r\n" +
            "72DGTeKSq2opD3YmlGcioL5HRQm1+yD4g5J4djBjypoAWKp8bniyK3FK7xbAOdU8\r\n" +
            "zNyfpuy7A+kxAbuNgeq+BpQJkSV5WgDtgoe4YvxHL00WvfZgKcp+thct8u5P/7SY\r\n" +
            "vJiMHm10Zst4y3pQIQQZ7QbnNWO17hfBfywSnX+6t48K/ru6XXH/3n/ZowXIU7rs\r\n" +
            "dE7c38UvJiyxU12evk5hWQIDAQABo4G/MIG8MB0GA1UdDgQWBBQf2+FnWR4P+CQd\r\n" +
            "gnw1vUJoduklkDCBjAYDVR0jBIGEMIGBgBQf2+FnWR4P+CQdgnw1vUJoduklkKFe\r\n" +
            "pFwwWjELMAkGA1UEBhMCY24xCzAJBgNVBAgTAnNkMQswCQYDVQQHEwJxZDEOMAwG\r\n" +
            "A1UEChMFcWR1bXMxDTALBgNVBAsTBHBvc3AxEjAQBgNVBAMTCXFkdW1zLmNvbYIJ\r\n" +
            "AM8rN7zT3uP9MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAKHNtmCA\r\n" +
            "e/ymL0KPseDizNCfCcjz4HJ/Vulpgy+yte0xlPcYE5iesRK/wre8qt3xg27EBxv3\r\n" +
            "9Dk/yYvyrwPfwIsSKEuMW93YvhzeroqfvBr/w18XC7yufx9KXKzvCNBGuPcK7/6m\r\n" +
            "7qJdPjs6zRdK/Thshi0htDycdsz+O5phDAbdllWweUUZ+zODjnA+K/MsU46Z9KP4\r\n" +
            "/ydXtSMM/AGFgN2hCsEl5whUi7leqs0/3Z9OZQDkZATUBheW5G5hawd7Y/xPt+8i\r\n" +
            "ydaZNaTQXgNUPEjeaVqYHEFg19NGWlFFQw8Jh34+JSEGfS8hhS0hL1J+idm0bj4D\r\n" +
            "7qkm0yyXkJzgvQQ=\r\n" +
            "-----END CERTIFICATE-----\r\n";

    public static void main(String[] args) {
        System.out.println("start net test");
/*        SocketCommu socketCommu = new SocketCommu("58.56.99.77", 8901);
        socketCommu.setCertInfo(CERT_INFO.getBytes());
        socketCommu.setSSLRequest(true);
        socketCommu.send(ByteUtils.hexString2ByteArray("00576002450000603100266000000000000000000000000000000000000000000008000020001000C0001200000300053030303030000000000000000000000000000000000000000000000000110000000100400003303120"));
        byte[] data = socketCommu.recv();
        System.out.println("read data = " + ByteUtils.byteArray2HexString(data));*/

        /*System.out.println("start net test");
        SocketCommu socketCommu = new SocketCommu("posapi.iboxpay.com", 443);
        socketCommu.setSSLRequest(true);
        socketCommu.send(content.getBytes());
        byte[] data = socketCommu.recv();
        System.out.println(new String(data));*/

        System.out.println("start net test");
        SocketCommu socketCommu = new SocketCommu("59.151.25.202", 29000);
        //socketCommu.setSSLRequest(true);
        socketCommu.send(ByteUtils.hexString2ByteArray("006F313031323137303134334A32303230303231373031202020202020202020563230323030323238303120202020202020202030303030333930323830303831303030303135392020202020202020202020202020202020202020202020202020202020202020202020202020202016"));
        byte[] data = socketCommu.recv();
        System.out.println("recv data = " + new String(data));
    }

}